namespace _206 {

    export function reverseList<T>(head: ListNode<T>): ListNode<T> {
        var newHead: ListNode<T> = null;
        while(head !== null) {
            var tmp = head;
            head = head.next;
            tmp.next = newHead;
            newHead = tmp;
        }
        return newHead;
    };

    export function toList(xs: number[]) {
        return xs.reduceRight((tail: ListNode<number>, x: number) => ({ val:x, next: tail }), null);
    }

    export function toArray(head: ListNode<number>): number[] {
        var result: number[] = [];
        while(head !== null) {
            result.push(head.val);
            head = head.next;
        }
        return result;
    }
}

var xs = _206.toArray( _206.reverseList( _206.toList([ 0, 1])))

console.log('the end')